// from http://www.learningjquery.com/2007/10/a-plugin-development-pattern

// create closure
//
(function(jQuery) {
    //
    // plugin definition
    //
    jQuery.fn.hilight = function(options) {
        debug(this);
        // build main options before element iteration
        var opts = jQuery.extend({}, jQuery.fn.hilight.defaults, options);
        // iterate and reformat each matched element
        return this.each(function() {
            $this = jQuery(this);
            // build element specific options
            var o = jQuery.meta ? jQuery.extend({}, opts, $this.data()) : opts;
            // update element styles
            $this.css({
                backgroundColor: o.background,
                color: o.foreground
            });
            var markup = $this.html();
            // call our format function
            markup = jQuery.fn.hilight.format(markup);
            $this.html(markup);
        });
    };
    //
    // private function for debugging
    //
    function debug($obj) {
        if (window.console && window.console.log)
        window.console.log('hilight selection count: ' + $obj.size());
    };
    //
    // define and expose our format function
    //
    jQuery.fn.hilight.format = function(txt) {
        return '<strong>' + txt + '</strong>';
    };
    //
    // plugin defaults
    //
    jQuery.fn.hilight.defaults = {
        foreground: 'red',
        background: 'yellow'
    };
    //
    // end of closure
    //
    })(jQuery);